Skip to content

Ft/build account switcher panel#168

Open
B3RN153 wants to merge 8 commits into
mainfrom
ft/build_account_switcher_panel
Open

Ft/build account switcher panel#168
B3RN153 wants to merge 8 commits into
mainfrom
ft/build_account_switcher_panel

Conversation

@B3RN153

@B3RN153 B3RN153 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor
  • Built an account switcher panel which displays the names of the current logged in users.
  • The currently active user is shown with a check.
  • The "Add Account" button redirects to login page.
  • If more than 3 users have sessions then the "Add Account" button will be disabled and a text will be shown.

Screenshots:
image
image

@B3RN153 B3RN153 self-assigned this Jul 6, 2026
@B3RN153 B3RN153 linked an issue Jul 6, 2026 that may be closed by this pull request
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 0c96a8b2-b3c7-4c4c-b09c-e12c89b891bb

📥 Commits

Reviewing files that changed from the base of the PR and between 7b20e02 and 62f4f3b.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • src/app/screens/DraftingScreen.tsx
  • src/components/ui/AccountSwitcherPanel.tsx
💤 Files with no reviewable changes (2)
  • src/app/screens/DraftingScreen.tsx
  • src/components/ui/AccountSwitcherPanel.tsx

📝 Walkthrough

Walkthrough

Adds account-switching functionality: a DB query (getUserById), account display utilities, useActiveAccountSummary and useDeviceAccounts hooks, AccountInitialsButton and AccountSwitcherPanel components, and integration into DraftingHeader and DraftingScreen.

Changes

Account switching feature

Layer / File(s) Summary
Data layer: DB query, types, and display utilities
src/db/queries.ts, src/types/db/types.ts, src/utils/accountDisplay.ts
Adds UserRow type, getUserById query with row validation via isUserRow, and getAccountDisplayName/getAccountInitials helpers.
Account data hooks
src/hooks/useActiveAccountSummary.ts, src/hooks/useDeviceAccounts.ts
Adds hooks that fetch active account summary and device account lists, with request-ordering and unmount guards.
Account UI components
src/components/ui/AccountInitialsButton.tsx, src/components/ui/AccountSwitcherPanel.tsx
Adds an initials avatar button and a bottom-sheet account switcher modal listing accounts with active state, limit messaging, and add-account action.
Integration into DraftingHeader and DraftingScreen
src/components/layout/DraftingHeader.tsx, src/app/screens/DraftingScreen.tsx
Extends header with an account indicator button and wires the switcher panel and active-account summary into all DraftingScreen render paths, removing the active player bar rendering.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DraftingScreen
  participant useActiveAccountSummary
  participant DraftingHeader
  participant AccountInitialsButton
  participant AccountSwitcherPanel
  participant useDeviceAccounts
  participant getUserById

  DraftingScreen->>useActiveAccountSummary: fetch summary keyed by refreshKey
  useActiveAccountSummary-->>DraftingScreen: account details
  DraftingScreen->>DraftingHeader: renderHeader() with account props
  DraftingHeader->>AccountInitialsButton: showAccountIndicator, onAccountPress
  AccountInitialsButton-->>DraftingScreen: onPress opens switcher
  DraftingScreen->>AccountSwitcherPanel: renderAccountSwitcher() visible=true
  AccountSwitcherPanel->>useDeviceAccounts: visible=true triggers reload()
  useDeviceAccounts->>getUserById: fetch user by known userId
  getUserById-->>useDeviceAccounts: DBTypes.User or null
  useDeviceAccounts-->>AccountSwitcherPanel: accounts, hasAccountLimit, loading
  AccountSwitcherPanel-->>DraftingScreen: onClose closes panel
Loading

Possibly related issues

  • Build Account Switcher Panel #84: Implements the account switcher panel, active-account rows, initials button, and 3-account limit behavior described in the issue.

Possibly related PRs

  • eten-tech-foundation/fluent-mobile#131: Both PRs modify src/app/screens/DraftingScreen.tsx and src/components/layout/DraftingHeader.tsx, with this PR extending the header structure introduced there.

Suggested reviewers: LijuJacob08, mattrace-gloo

Poem

A rabbit hops from account to account,
Initials glowing in a circle so round,
A panel slides up, a switch, a click,
New names appear, the list grows quick,
Hop, hop, hooray — one account, then more! 🐇✨

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly points to the main change: building the account switcher panel.
Description check ✅ Passed The description matches the changeset, describing the account switcher panel, active-user checkmark, and Add Account behavior.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ft/build_account_switcher_panel

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (5)
src/utils/accountDisplay.ts (1)

1-45: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider adding unit tests for the initials/display-name branching logic.

Several edge cases (missing names, whitespace-only names, single vs. multi-part email local-parts) are handled correctly, but the branching is non-trivial and easy to regress silently.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/utils/accountDisplay.ts` around lines 1 - 45, Add unit tests for the
branching in getAccountDisplayName and getAccountInitials in accountDisplay.ts,
covering missing names, whitespace-only first/last names, email fallback
behavior, and both single-part and multi-part email local-parts. Use the public
helpers getAccountDisplayName, getAccountInitials, and the internal behaviors
around buildEmailFallback/firstCharacter as the cases to verify so regressions
in these edge paths are caught.
src/app/screens/DraftingScreen.tsx (1)

22-24: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove leftover commented-out code.

// useDraftingContext, and {/* <DraftingPlayerBar verses={verses} /> */} are dead code left in from the refactor.

🧹 Cleanup
 import {
   DraftingProvider,
-  // useDraftingContext,
-          {/* <DraftingPlayerBar verses={verses} /> */}
-

Also applies to: 200-200

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/app/screens/DraftingScreen.tsx` around lines 22 - 24, Remove the leftover
commented-out code from the Drafting screen refactor. In DraftingScreen, delete
the unused commented import `useDraftingContext` and the commented JSX for
`DraftingPlayerBar`, keeping only the active imports and rendered components.
Use the identifiers DraftingScreen, DraftingProvider, useDraftingContext, and
DraftingPlayerBar to locate the dead code and clean it out.
src/components/ui/AccountSwitcherPanel.tsx (2)

47-53: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Backdrop Pressable may swallow taps on non-interactive sheet areas.

The sheet body (Line 48) is a plain View nested inside the backdrop Pressable. Taps on padding/gaps within the sheet (not on a TouchableOpacity) will likely bubble up and trigger onClose, closing the modal unexpectedly.

🔧 Proposed fix to stop propagation on the sheet
-        <View
+        <Pressable
+          onPress={() => {}}
           style={[
             styles.sheet,
             { paddingBottom: insets.bottom + theme.spacing.lg },
           ]}
         >
           ...
-        </View>
+        </Pressable>
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/ui/AccountSwitcherPanel.tsx` around lines 47 - 53, The
backdrop Pressable in AccountSwitcherPanel is wrapping the entire sheet, so taps
on non-interactive areas inside the sheet can still trigger onClose. Move the
close handler to the backdrop only and stop touch propagation for the sheet
container itself, using the existing Pressable/View structure around
styles.backdrop and styles.sheet so taps inside the sheet body do not dismiss
the modal unexpectedly.

160-161: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Hardcoded hex/rgba colors alongside theme tokens.

'rgba(10, 18, 40, 0.44)', '#F3F7FF', '#2E5BD8', '#F1F4FA' are hardcoded even though the rest of the stylesheet consistently uses theme.colors.*. Consider adding equivalent theme tokens for consistency and easier future theming (e.g., dark mode).

Also applies to: 208-211, 222-223, 266-267

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/ui/AccountSwitcherPanel.tsx` around lines 160 - 161, Replace
the remaining hardcoded color values in AccountSwitcherPanel’s stylesheet with
theme-backed values to match the existing `theme.colors.*` pattern. Update the
styles around the background and text/border states referenced in
`AccountSwitcherPanel` (including the selection, hover, and divider-related
styles) so they use equivalent tokens instead of `rgba(10, 18, 40, 0.44)`,
`#F3F7FF`, `#2E5BD8`, and `#F1F4FA`. If matching tokens do not exist yet, add
them to the theme and then consume them here.
src/hooks/useActiveAccountSummary.ts (1)

25-41: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicated cancellation-guard boilerplate across hooks.

The mountedRef/requestIdRef setup and cleanup effect (Lines 29-37) is duplicated almost verbatim in src/hooks/useDeviceAccounts.ts (Lines 33-41). Consider extracting a small shared hook (e.g. useCancellableAsync() returning { mountedRef, nextRequestId }) to keep the guard logic consistent and avoid maintaining it in two places.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks/useActiveAccountSummary.ts` around lines 25 - 41, The
mountedRef/requestIdRef cancellation guard in useActiveAccountSummary is
duplicated in useDeviceAccounts, so extract the shared lifecycle/request
tracking into a small reusable hook such as useCancellableAsync that exposes the
mounted state and a nextRequestId helper. Then update useActiveAccountSummary
and useDeviceAccounts to consume that shared hook instead of each defining their
own refs and cleanup effect, keeping the cancellation logic centralized and
consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/app/screens/DraftingScreen.tsx`:
- Around line 80-105: The account switch flow is wired to pass onUserSwitched
into AccountSwitcherPanel, but the row taps inside that component never invoke
it, so selecting an account does nothing. Update the AccountSwitcherPanel
account-row press handling to call the provided onUserSwitched callback when a
user row is tapped, and ensure DraftingScreen’s handleUserSwitched is reached
through that path. Keep the existing close behavior intact while adding the
missing tap handler on the account item component(s).

In `@src/components/ui/AccountSwitcherPanel.tsx`:
- Around line 21-30: The account rows in AccountSwitcherPanel are currently
non-interactive because onUserSwitched is never destructured or used, and the
row UI has no press handler. Update the AccountSwitcherPanel component to accept
onUserSwitched alongside visible and onClose, wire each account row’s onPress to
the existing switchActiveUser flow, and invoke onUserSwitched after a successful
switch so the parent DraftingScreen can refresh state.

---

Nitpick comments:
In `@src/app/screens/DraftingScreen.tsx`:
- Around line 22-24: Remove the leftover commented-out code from the Drafting
screen refactor. In DraftingScreen, delete the unused commented import
`useDraftingContext` and the commented JSX for `DraftingPlayerBar`, keeping only
the active imports and rendered components. Use the identifiers DraftingScreen,
DraftingProvider, useDraftingContext, and DraftingPlayerBar to locate the dead
code and clean it out.

In `@src/components/ui/AccountSwitcherPanel.tsx`:
- Around line 47-53: The backdrop Pressable in AccountSwitcherPanel is wrapping
the entire sheet, so taps on non-interactive areas inside the sheet can still
trigger onClose. Move the close handler to the backdrop only and stop touch
propagation for the sheet container itself, using the existing Pressable/View
structure around styles.backdrop and styles.sheet so taps inside the sheet body
do not dismiss the modal unexpectedly.
- Around line 160-161: Replace the remaining hardcoded color values in
AccountSwitcherPanel’s stylesheet with theme-backed values to match the existing
`theme.colors.*` pattern. Update the styles around the background and
text/border states referenced in `AccountSwitcherPanel` (including the
selection, hover, and divider-related styles) so they use equivalent tokens
instead of `rgba(10, 18, 40, 0.44)`, `#F3F7FF`, `#2E5BD8`, and `#F1F4FA`. If
matching tokens do not exist yet, add them to the theme and then consume them
here.

In `@src/hooks/useActiveAccountSummary.ts`:
- Around line 25-41: The mountedRef/requestIdRef cancellation guard in
useActiveAccountSummary is duplicated in useDeviceAccounts, so extract the
shared lifecycle/request tracking into a small reusable hook such as
useCancellableAsync that exposes the mounted state and a nextRequestId helper.
Then update useActiveAccountSummary and useDeviceAccounts to consume that shared
hook instead of each defining their own refs and cleanup effect, keeping the
cancellation logic centralized and consistent.

In `@src/utils/accountDisplay.ts`:
- Around line 1-45: Add unit tests for the branching in getAccountDisplayName
and getAccountInitials in accountDisplay.ts, covering missing names,
whitespace-only first/last names, email fallback behavior, and both single-part
and multi-part email local-parts. Use the public helpers getAccountDisplayName,
getAccountInitials, and the internal behaviors around
buildEmailFallback/firstCharacter as the cases to verify so regressions in these
edge paths are caught.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 941218ea-d516-4247-b8c6-35736400c153

📥 Commits

Reviewing files that changed from the base of the PR and between ba17c69 and 7b20e02.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (10)
  • package.json
  • src/app/screens/DraftingScreen.tsx
  • src/components/layout/DraftingHeader.tsx
  • src/components/ui/AccountInitialsButton.tsx
  • src/components/ui/AccountSwitcherPanel.tsx
  • src/db/queries.ts
  • src/hooks/useActiveAccountSummary.ts
  • src/hooks/useDeviceAccounts.ts
  • src/types/db/types.ts
  • src/utils/accountDisplay.ts

Comment thread src/app/screens/DraftingScreen.tsx Outdated
Comment thread src/components/ui/AccountSwitcherPanel.tsx
@B3RN153 B3RN153 mentioned this pull request Jul 8, 2026
@B3RN153 B3RN153 enabled auto-merge (squash) July 10, 2026 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build Account Switcher Panel

1 participant